package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.domain.db.QuestionUserLock;
import com.tanhua.dubbo.mapper.LockMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author HoshizoraL
 * @Date 2021/4/21 9:26
 */
@Service
public class LockServiceApiImpl implements LockServiceApi {

    @Autowired
    private LockMapper lockMapper;

    @Override
    public void update(long l, Long userId) {
        QuestionUserLock lock = new QuestionUserLock();
        lock.setQuestionnaireId((int)l);
        QueryWrapper<QuestionUserLock> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",userId);
        lockMapper.update(lock,wrapper);
    }

    @Override
    public int getLock(Long userId) {
        return lockMapper.selectOne(new QueryWrapper<QuestionUserLock>().eq("user_id",userId)).getQuestionnaireId();
    }
}
